import { lib, game, ui, get, ai, _status } from "../../../noname.js";
export default {
    name: "DALF_isotope",
    character: {
        "DALF_TobiichiOrigami_Umgekehrt": ["female", "shen", 3,
            ["DALF_anyu", "DALF_chuishe", "DALF_wuwang"],
            ["name:鸢一|折纸"]
        ],
        "DALF_HonjouNia_Umgekehrt": ["female", "shen", 3,
            ["DALF_kuangshu", "DALF_xushi"],
            ["name:本条|二亚"]
        ],
        "DALF_HimekawaYoshino_Umgekehrt": ["female", "shen", 4,
            ["DALF_IcePuppe", "DALF_fengdong", "DALF_shenhan"],
            ["name:氷芽川|四糸乃"]
        ],
        "DALF_YatogamiTenka_Umgekehrt": ["female", "shen", 5,
            ["DALF_moren", "DALF_huanmie", "DALF_baonve", "DALF_zhongyan"],
            ["name:夜刀神|天香"]
        ]
    },
    translate: {
        "DALF_isotope": "反转体",


        "DALF_TobiichiOrigami_Umgekehrt": "反转鸢一折纸",
        "DALF_TobiichiOrigami_Umgekehrt_prefix": "反转",
        "DALF_TobiichiOrigami_Umgekehrt_ab": "鸢一折纸",
        "DALF_anyu": "黯羽",
        "DALF_anyu_info": "出牌阶段限一次，你可以与所有可拼点的其他角色共同拼点。然后你对所有点数大于你或小于你的角色依次视为使用两张【五谷丰登】。",
        "DALF_chuishe": "垂赦",
        "DALF_chuishe_info": "你的回合内，当其他角色进入濒死状态时，若你已受伤，其可以弃置你的一张手牌，与你各回复1点体力。",
        "DALF_wuwang": "无妄",
        "DALF_wuwang_info": "当你失去最后的手牌时，你可以令本回合获得过牌的所有角色各选择一项：1.交给你一张牌并令你摸一张牌；2.受到1点无来源伤害并令你补充护甲至1点。",


        "DALF_HonjouNia_Umgekehrt": "反转本条二亚",
        "DALF_HonjouNia_Umgekehrt_prefix": "反转",
        "DALF_HonjouNia_Umgekehrt_ab": "本条二亚",
        "DALF_kuangshu": "诳书",
        // "DALF_kuangshu_info": "每回合每种类型牌限一次，你可以使用弃牌堆底二十张牌中除【无懈可击】外的一张牌。",
        "DALF_kuangshu_info": "锁定技，游戏开始时，你摸两张牌并明置之。当你失去牌时，若你当前阶段内未以此法外的方式获得过牌，则以弃牌堆底的牌依次将你的明置牌补至两张。",
        "DALF_xushi": "叙史",
        "DALF_xushi_info": "锁定技，你失去的牌或你使用的牌结算完、进入弃牌堆后，将之洗入牌堆。",


        "DALF_HimekawaYoshino_Umgekehrt": "反转氷芽川四糸乃",
        "DALF_HimekawaYoshino_Umgekehrt_prefix": "反转",
        "DALF_HimekawaYoshino_Umgekehrt_ab": "四糸乃",
        "DALF_IcePuppe": "冰傀",
        "DALF_IcePuppe_info": "其他角色回合被跳过后，你可以获得其一张牌，令其获得一个回合、并于该回合后翻面。<br>当你处于濒死状态时，已翻面的角色可以翻面并摸一张牌，视为对你使用【桃】。",
        "DALF_IcePuppe_chenci": "冰傀",
        "DALF_IcePuppe_chenci_info": "有〖冰傀〗的角色处于濒死状态时，你可以翻回正面，摸一张牌，视为对其使用【桃】。",
        "DALF_fengdong": "封冻",
        "DALF_fengdong_info": "你攻击范围内的角色受到伤害时，若其未翻面，你可以弃置一张黑色手牌令其翻面，该伤害值-1。且其非锁定技失效直到其下次翻面；其下次受到伤害后，可以失去1点体力翻回正面。",
        "DALF_shenhan": "深寒",
        "DALF_shenhan_info": "锁定技，每回合限一次，一名角色翻回正面后，你摸一张牌。你于一轮内第四次发动该技能后，你令一名角色翻面。",


        "DALF_YatogamiTenka_Umgekehrt": "反转夜刀神十香",
        "DALF_YatogamiTenka_Umgekehrt_prefix": "反转",
        "DALF_YatogamiTenka_Umgekehrt_ab": "夜刀神天香",
        "DALF_moren": "魔刃",
        "DALF_moren_info": "其他角色使用武器牌结算完后，你可以获得此牌的复制。摸牌阶段，你可以使用一张装备牌，将摸牌数改为X（若该装备牌为武器，则X为攻击范围，否则X为装备副类别编号）。",
        "DALF_moren_tip": "注意事项",
        "DALF_moren_tip_info": "若你因为其它技能先将摸牌阶段的摸牌数减少至1或0，则你不能通过使用攻击范围为0或1的武器牌再进一步减少摸牌数。",
        "DALF_huanmie": "幻灭",
        "DALF_huanmie_info": "锁定技，你手牌中的装备牌不计入手牌上限，且在出牌阶段内均视为【杀】；你由装备牌转化的【杀】目标上限为X、且不能被点数为X的倍数【闪】响应（多张装备牌转化【杀】取X为最大值）。",
        "DALF_baonve": "暴虐",
        "DALF_baonve_info": "锁定技，准备阶段，你除非重铸一张武器牌，否则失去1点体力、展示手牌并弃置其中所有基本牌。",
        "DALF_zhongyan": "终焉",
        "DALF_zhongyan_info": "锁定技，其他角色死亡时，你选择废除一个非武器装备栏或减1点体力上限，然后获得一个武器栏，回复1点体力。",

    },
    dynamicTranslate: {
        DALF_huanmie: function (player) {
            if (player.hasSkill('DALF_moren')) return lib.translate['DALF_huanmie_info'];
            return lib.translate['DALF_huanmie_info'].replace('（', '（若该装备牌为武器，则X为攻击范围，否则X为装备副类别编号，');
        },
    },
    /** @type { importCharacterConfig['skill'] } */
    skill: {

        /*反转鸢一折纸*/
        "DALF_anyu": {
            audio: "ext:约会大作战/audio:2",
            marktext: "赢",
            intro: {
                name: "黯羽",
                markcount: () => 0
            },
            enable: "phaseUse",
            usable: 1,
            filter(event, player) {
                return game.hasPlayer(function (current) {
                    return player.canCompare(current);
                });
            },
            filterTarget(card, player, target) {
                return player.canCompare(target);
            },
            selectTarget: -1,
            multitarget: true,
            multiline: true,
            content: function () {
                "step 0"
                var next = player.chooseToCompare(targets);
                next.set('check', function (card) {
                    if (typeof card == 'string' && lib.skill[card])
                        return lib.skill[card].check || function () { return 0 }();
                    var addi = (get.value(card) >= 8 && get.type(card) != 'equip') ? 3 : 0;
                    if (card.name == 'du') addi += 3;
                    return 20 - get.number(card) / 2 - get.value(card) - addi;
                });
                next.setContent('chooseToCompareMeanwhile');
                "step 1"
                if (result) {
                    event.winer = [], event.loser = [];
                    for (let i = 0; i < targets.length; i++) {
                        if (result.num1[i] < result.num2[i]) {
                            event.winer.push(targets[i]);
                            targets[i].addMark('DALF_anyu', 1, false);
                        } else if (result.num1[i] > result.num2[i]) {
                            event.loser.push(targets[i]);
                        }
                    }
                } else event.finish();
                "step 2"
                if (event.winer.length > 0) {
                    if (event.loser.length > 0) {
                        const dialog = ui.create.dialog('###黯羽###请选择【五谷丰登】的目标');
                        dialog.add([
                            [
                                [0, '<b>赢&ensp;的&ensp;角&ensp;色</b><br>'],
                                [1, '<b>输&ensp;的&ensp;角&ensp;色</b><br>']
                            ], 'tdnodes'
                        ]);
                        ui.create.buttons(event.winer, 'player', dialog.buttons[0], true, true);
                        ui.create.buttons(event.loser, 'player', dialog.buttons[1], true, true);
                        var next = player.chooseButton(dialog, true);
                        next.set('ai', function (button) {
                            return _status.event.checkx(button.link, _status.event.targetList);
                        });
                        next.set('checkx', function (n, players) {
                            const player = get.player(),
                                cardx = { name: 'wugu', isCard: true };
                            let value = 0;
                            for (let i of players)
                                if (player.canUse(cardx, i))
                                    value += get.effect(i, cardx, player, player) * 2;
                            return value;
                        });
                        next.set('targetList', [event.winer, event.loser]);
                    } else event._result = { bool: true, links: event.winer };
                } else if (event.loser.length > 0) {
                    event._result = { bool: true, links: event.loser };
                } else event.finish();
                "step 3"
                game.countPlayer(function (current) {
                    current.removeMark('DALF_anyu', 1, false);
                });
                if (result.bool) {
                    var cardx = { name: 'wugu', isCard: true },
                        targets = event[result.links[0] ? 'loser' : 'winer'];
                    player.line(targets, { color: [0, 0, 205] })
                    player.useCard(cardx, targets, 'noai');
                    player.useCard(cardx, targets, 'noai');
                }
            },
            ai: {
                order: 8,
                result: {
                    target: -1,
                    player: 2
                }
            }
        },
        "DALF_chuishe": {
            audio: "ext:约会大作战/audio:2",
            trigger: {
                global: "dying"
            },
            direct: true,
            filter: function (event, player) {
                return player == _status.currentPhase &&
                    event.player != player &&
                    player.isDamaged();
            },
            content: function () {
                "step 0"
                trigger.player.choosePlayerCard('h', player)
                    .set('chooseonly', true)
                    .set('ai', function (button) {
                        if (_status.event.att > 0) {
                            if (_status.event.needLose) return 10;
                            return 6 - get.value(button.link);
                        }
                        if (_status.event.needLose) return 0;
                        return 6 + get.value(button.link);
                    })
                    .set('att', trigger.player.attitudeTo(player))
                    .set('needLose', player.countCards('h') == 1 &&
                        player.hasSkill('DALF_wuwang'))
                    .set('prompt', get.prompt2('DALF_chuishe', player));
                "step 1"
                if (result.bool) {
                    player.logSkill('DALF_chuishe', trigger.player);
                    player.discard(result.cards)
                        .set('notBySelf', true)
                        .set('discarder', trigger.player)
                        .set("delay", false);
                    trigger.player.recover();
                    player.recover();
                }
            },
        },
        "DALF_wuwang": {
            audio: "ext:约会大作战/audio:2",
            trigger: {
                global: ["equipEnd", "addJudgeEnd", "gainEnd",
                    "loseAsyncEnd", "addToExpansionEnd"
                ],
                player: "loseEnd"
            },
            frequent: function (event, player) {
                return !game.hasPlayer(function (current) {
                    if (current == player) return false;
                    if (player.attitudeTo(current) < 0) return false;
                    return current.getHistory('gain').length;
                });
            },
            filter: function (event, player) {
                if (player.countCards('h')) return false;
                var evt = event.getl(player);
                if (!evt || evt.player != player || !evt.hs || !evt.hs.length) return false;
                event.DALF_wuwangTargets = game.filterPlayer(function (current) {
                    if (current == player) return false;
                    return current.getHistory('gain').length > 0;
                });
                return event.DALF_wuwangTargets.length > 0;
            },
            check: function (event, player) {
                return true;
                // var value = 0.5;
                // if (
                //     game.countPlayer(function(current) {
                //         if (current == player) return false;
                //         if (current.getHistory('gain').length > 0) {
                //             let bv = 1;
                //             if (player.attitudeTo(current) > 0) bv *= -1;
                //             if (!current.countCards('h')) bv *= 2;
                //             value += bv;
                //             return true;
                //         }
                //     }) == 1
                // ) return true;
                // return value > 0;
            },
            logTarget: "DALF_wuwangTargets",
            content: function () {
                "step 0"
                event.players = trigger.DALF_wuwangTargets.slice(0).sortBySeat(_status.currentPhase);
                event.supporter = [];
                "step 1"
                event.target = event.players.shift();
                var next = event.target.chooseCard('he');
                next.set('ai', function (card) {
                    if (_status.event.att > 0)
                        return 8 - get.value(card);
                    if (get.tag(card, 'recover') || get.tag(card, 'save'))
                        return 0;
                    if (_status.event.player.hp == 1)
                        return 0;
                    return 6.5 - get.value(card);
                });
                next.set('prompt', '无妄');
                next.set('prompt2', '将一张牌交给' + get.translation(player) + '，或取消并受到一点伤害');
                "step 2"
                if (result.bool) {
                    event.target.give(result.cards, player);
                    player.draw();
                } else {
                    event.target.damage('nosource');
                    if (player.hujia < 1) player.changeHujia(1);
                }
                if (event.players.length) event.goto(1);
            },
            ai: {
                noh: true,
                skillTagFilter: function (player) {
                    if (!lib.skill['DALF_wuwang'].check(_status.event, player))
                        return false;
                }
            }
        },

        /*反转本条二亚*/
        // "DALF_kuangshu": {
        //     audio: "ext:约会大作战/audio:2",
        //     init: function(player, skill) {
        //         if (!player.storage[skill])
        //             player.storage[skill] = [];
        //     },
        //     enable: "chooseToUse",
        //     filter: function(event, player) {
        //         var countNode = ui.discardPile.childElementCount,
        //             types = player.storage['DALF_kuangshu'];
        //         for (let i = 1; i <= countNode; i++) {
        //             if (i > 20) break;
        //             let card = ui.discardPile.childNodes[countNode - i];
        //             if (get.name(card) == 'wuxie') continue;
        //             if (types.includes(get.type2(card))) continue;
        //             if (event.filterCard(card, player, event)) return true;
        //         }
        //         return false;
        //     },
        //     hiddenCard: function(player, name) {
        //         if (name == 'wuxie') return false;
        //         return !player.storage['DALF_kuangshu'].includes(get.type2({ name: name }));
        //     },
        //     chooseButton: {
        //         dialog: function(event, player) {
        //             var countNode = ui.discardPile.childElementCount,
        //                 list = [];
        //             for (let i = 1; i <= countNode; i++) {
        //                 if (i > 20) break;
        //                 list.unshift(ui.discardPile.childNodes[countNode - i]);
        //             }
        //             return ui.create.dialog('###诳书###请选择要使用的牌', [list, 'card']);
        //         },
        //         filter: function(button, player) {
        //             if (get.name(button.link) == 'wuxie') return false;
        //             if (player.storage['DALF_kuangshu'].includes(get.type2(button.link))) return false;
        //             return _status.event.getParent().filterCard(button.link, player, _status.event.getParent());
        //         },
        //         check: function(button) {
        //             var event = _status.event.getParent();
        //             if (event.type == 'dying' && get.attitude2(event.dying) < 0) return 0;
        //             return _status.event.player.getUseValue(button.link, true, true);
        //         },
        //         backup: function(links, player) {
        //             var backup = {
        //                 filterCard: () => false,
        //                 selectCard: -1,
        //                 viewAs: links[0],
        //                 cards: links,
        //                 onuse: function(result, player) {
        //                     player.logSkill('DALF_kuangshu');
        //                     result.cards = links;
        //                     player.addTempSkill('DALF_kuangshu_limitType');
        //                     player.storage['DALF_kuangshu'].add(get.type2(result.card));
        //                 }
        //             };
        //             backup.viewAs.cards = links;
        //             return backup;
        //         },
        //         prompt: function(links, player) {
        //             return '请选择' + get.translation(links[0]) + '的使用目标';
        //         }
        //     },
        //     ai: {
        //         order: 4,
        //         result: {
        //             player: 1
        //         }
        //     },
        //     subSkill: {
        //         limitType: {
        //             onremove: function(player) {
        //                 player.storage['DALF_kuangshu'] = [];
        //             },
        //             sub: true
        //         }
        //     }
        // },
        "DALF_kuangshu": {
            audio: "ext:约会大作战/audio:2",
            mod: {
                aiOrder(card, player, num) {
                    if (get.is.shownCard(card)) return num + 3;
                }
            },
            trigger: {
                global: [
                    "phaseBefore", "gainEnd",
                    "equipEnd", "addJudgeEnd",
                    "loseAsyncEnd", "addToExpansionEnd"
                ],
                player: ["enterGame", "loseEnd"]
            },
            // usable: 20,
            forced: true,
            filter(event, player) {
                switch (event.name) {
                    case 'enterGame':
                        return true;
                    case 'phase':
                        return game.phaseNumber == 0;
                    case 'gain':
                        if (event.player == player)
                            return false;
                    default:
                        if (player.countCards('h', cardx => {
                            return get.is.shownCard(cardx);
                        }) >= 2) return false;
                }
                const phase = event.getParent(evt => {
                    return evt.name.startsWith('phase') &&
                        evt.name.length > 5;
                });
                if (phase && player.hasHistory('gain', evt => {
                    const curPhase = evt.getParent(evt2 => {
                        return evt2.name.startsWith('phase') &&
                            evt2.name.length > 5;
                    });
                    return phase == curPhase && !evt.DALF_kuangshu;
                })) return false;
                const evt = event.getl(player);
                return evt && evt.hs && evt.hs.length > 0;
            },
            async content(event, trigger, player) {
                if (trigger.name == 'enterGame' || trigger.name == 'phase') {
                    const cards = await player.draw(2).forResult();
                    player.addShownCards(cards, 'visible_DALF');
                } else
                    while (
                        player.countCards('h', cardx => {
                            return get.is.shownCard(cardx);
                        }) < 2
                    ) {
                        if (ui.discardPile.childElementCount > 0) {
                            const cards = await player.gain('draw2',
                                ui.discardPile.firstElementChild)
                                .set('DALF_kuangshu', true).cards;
                            await player.addShownCards(cards, 'visible_DALF');
                        } else break;
                    }
            },
            ai: {
                effect: {
                    player_use(card, player, target) {
                        if (get.is.shownCard(card)) return [1, 0.8];
                    },
                    target(card, source, player) {
                        let count = 0;
                        if (get.tag(card, "loseCard") &&
                            (player.countCards('he', cardx => {
                                if (get.is.shownCard(cardx)) {
                                    count++;
                                    return false;
                                }
                                return true;
                            }) == 0 && count <= 2)
                        ) return 0.5;
                    }
                }
            },
            global: ["DALF_kuangshu_ai"],
            subSkill: {
                ai: {
                    charlotte: true,
                    mod: {
                        aiValue(player, card, num) {
                            const owner = get.owner(card);
                            if (owner && owner.hasSkill('DALF_kuangshu') &&
                                get.is.shownCard(card)) return num - 3;
                        }
                    },
                    sub: true
                }
            }
        },
        "DALF_xushi": {
            audio: "ext:约会大作战/audio:2",
            trigger: {
                player: ["loseAfter", "useCardAfter"],
                global: "loseAsyncAfter"
            },
            forced: true,
            filter: function (event, player) {
                if (event.name == 'useCard')
                    return event.cards && event.cards.someInD();
                var evt = event.getl(player);
                return evt && evt.cards2.someInD('d');
            },
            content: function () {
                "step 0"
                var cards;
                if (trigger.name == 'useCard')
                    cards = trigger.cards.filterInD();
                else
                    cards = trigger.getl(player).cards2.filterInD('d');
                for (let i = 0; i < cards.length; i++) {
                    let p = Math.floor(Math.random() * ui.cardPile.childElementCount);
                    ui.cardPile.insertBefore(cards[i], ui.cardPile.childNodes[p]);
                }
                game.updateRoundNumber();
                game.log(cards, '洗入了牌堆');
            }
        },

        /*反转氷芽川四糸乃*/
        "DALF_IcePuppe": {
            audio: "ext:约会大作战/audio:2",
            trigger: {
                global: "phaseCancelled"
            },
            direct: true,
            filter: function (event, player) {
                return player != event.player &&
                    event.player.countGainableCards(player, 'he');
            },
            content: function () {
                "step 0"
                var next = player.gainPlayerCard(trigger.player, 'he');
                next.set('ai', function (button) {
                    if (_status.event.att > 0) {
                        return get.value(button.link, _status.event.player) -
                            get.value(button.link, _status.event.target);
                    }
                    return get.value(button.link);
                });
                next.set('prompt', get.prompt('DALF_IcePuppe', trigger.player));
                next.set('prompt2', '其他角色回合被跳过后，你可以获得其一张牌，令其获得一个回合、并于该回合后翻面。');
                next.set('logSkill', ['DALF_IcePuppe', trigger.player]);
                next.set('target', trigger.player);
                next.set('att', player.attitudeTo(trigger.player));
                "step 1"
                if (result.bool) {
                    trigger.player.insertPhase('DALF_IcePuppe');
                    trigger.player.insertEvent('turnOver', 'turnOver');
                }
            },
            ai: {
                threaten: 1.5
            },
            global: ["DALF_IcePuppe_chenci"],
            subSkill: {
                "chenci": {
                    trigger: { player: "chooseToUseBegin" },
                    filter: function (event, player) {
                        if (event.responded) return false;
                        if (event.type != 'dying') return false;
                        if (event.DALF_IcePuppe_chenci) return false;
                        if (!event.dying.hasSkill('DALF_IcePuppe')) return false;
                        if (!player.isTurnedOver()) return false;
                        if (!event.filterCard || !event.filterCard({ name: 'tao' }, player, event)) return false;
                        return true;
                    },
                    logTarget: "dying",
                    content: function () {
                        "step 0"
                        trigger.DALF_IcePuppe_chenci = true;
                        "step 1"
                        player.turnOver(false);
                        player.draw();
                        "step 2"
                        trigger.untrigger();
                        trigger.set('responded', true);
                        trigger.result = { bool: true, card: { name: 'tao', isCard: true }, targets: [trigger.dying] };
                    },
                    sub: true,
                }
            },
        },
        "DALF_fengdong": {
            audio: "ext:约会大作战/audio:2",
            trigger: {
                global: "damageBegin3",
            },
            direct: true,
            filter: function (event, player) {
                if (!player.countCards('h', { color: 'black' })) return false;
                return player.inRange(event.player) && !event.player.isTurnedOver();
            },
            content: function () {
                "step 0"
                var next = player.chooseToDiscard('h');
                next.set('filterCard', function (card) {
                    return get.color(card) == 'black';
                });
                next.set('ai', function (card) {
                    if (_status.event.att < 0) {
                        if (trigger.player.isTurnedOver()) return 0;
                        if (trigger.player.hp == 1 && !trigger.player.countCards('h')) return 0;
                        if (trigger.num <= 1) return 8 - get.value(card);
                    } else if (trigger.player.isTurnedOver()) {
                        return 7 - get.value(card);
                    }
                    return 0;
                });
                next.set('prompt', get.prompt2('DALF_fengdong', trigger.player));
                next.set('logSkill', ['DALF_fengdong', trigger.player]);
                next.set('att', get.attitude(player, trigger.player));
                "step 1"
                if (result.bool) {
                    trigger.player.turnOver();
                    trigger.num--;

                } else event.finish();
                "step 2"
                trigger.player.addTempSkill('fengyin', { player: 'turnOverBefore' });
                trigger.player.addTempSkill('DALF_fengdong_returnOver', { player: 'damageAfter' });
            },
            ai: {
                threaten: 1.7
            },
            subSkill: {
                returnOver: {
                    charlotte: true,
                    mark: true,
                    marktext: "冻",
                    intro: {
                        name: "封冻",
                        content: "你下次受到伤害后，你可以失去一点体力翻回正面"
                    },
                    trigger: { player: "damageEnd" },
                    check: function (event, player) {
                        if (player.hp < 2) return false;
                        return player.isTurnedOver();
                    },
                    prompt: "封冻：是否失去一点体力翻回正面？",
                    content: function () {
                        "step 0"
                        player.loseHp();
                        player.turnOver(false);
                    },
                    sub: true
                }
            }
        },
        "DALF_shenhan": {
            audio: "ext:约会大作战/audio:2",
            marktext: "深",
            intro: {
                name: "深寒",
                content: "本轮已发动&次"
            },
            trigger: {
                global: "turnOverAfter"
            },
            usable: 1,
            forced: true,
            filter: function (event, player) {
                return !event.player.isTurnedOver();
            },
            content: function () {
                "step 0"
                player.draw();
                player.addMark('DALF_shenhan', 1, false);
                "step 1"
                if (player.countMark('DALF_shenhan') == 4) {
                    var next = player.chooseTarget(true, '深寒：令一名角色翻面');
                    next.set('ai', function (target) {
                        var power = 1,
                            add = 0;
                        if (target.isTurnedOver()) power = -1, add = -5;
                        return -_status.event.player.attitudeTo(target) * power + add;
                    });
                } else event.finish();
                "step 2"
                if (result.bool) {
                    player.line(result.targets, { color: [30, 144, 255] });
                    result.targets[0].turnOver();
                }
            },
            group: ["DALF_shenhan_resetCount"],
            subSkill: {
                resetCount: {
                    trigger: { global: "roundStart" },
                    forced: true,
                    silent: true,
                    content: function () {
                        var count = player.countMark('DALF_shenhan');
                        if (count) player.removeMark('DALF_shenhan', count, false);
                    },
                    sub: true
                }
            }
        },

        /*反转夜刀神十香*/
        "DALF_moren": {
            audio: "ext:约会大作战/audio:1",
            trigger: {
                global: "useCardEnd",
                player: "phaseDrawBegin2"
            },
            frequent: true,
            direct: true,
            filter: function (event, player) {
                if (event.name != 'useCard') return player.hasCard({ type: 'equip' }, 'hs');
                return player != event.player && get.subtype(event.card) == 'equip1';
            },
            content: function () {
                "step 0"
                if (trigger.name == 'useCard') {
                    var next = player.chooseBool(
                        get.prompt('DALF_moren', trigger.card),
                        '其他角色使用武器牌结算完后，你可以获得此牌的复制。'
                    );
                    next.set('frequentSkill', 'DALF_moren');
                } else {
                    var next = player.chooseToUse({
                        filterCard: function (card, player, target) {
                            if (get.type(card) != 'equip') return false;
                            let num = parseInt(get.subtype(card).slice(5));
                            if (num == 1) {
                                let info = get.info(card);
                                if (info && info.distance && info.distance.attackFrom)
                                    num = -info.distance.attackFrom + 1;
                            }
                            return num >= 2 - _status.event.drawNum;
                        },
                        ai1: function (card) {
                            if (card.name.indexOf('zhuge') != -1) {
                                var player = _status.event.player;
                                if (!game.hasPlayer(function (current) {
                                    return player.distanceTo(current) == 1 &&
                                        get.effect(current, { name: 'sha' }, player) > 0
                                })) return 0;
                                return player.countCards('hs', 'sha') + player.countCards('hs', { type: 'equip' }) - 2;
                            }
                            let num = parseInt(get.subtype(card).slice(5));
                            if (num == 1) {
                                let info = get.info(card);
                                if (info && info.distance && info.distance.attackFrom)
                                    num = -info.distance.attackFrom + 1;
                            }
                            return num - 1;
                        },
                        prompt: get.prompt('DALF_moren'),
                        prompt2: '摸牌阶段，你可以使用一张装备牌，将摸牌数改为X（若该装备牌为武器，则X为攻击范围，否则X为装备副类别编号）。',
                        logSkill: 'DALF_moren',
                        drawNum: trigger.num
                    });
                    event.goto(2);
                }
                "step 1"
                if (result.bool) {
                    player.logSkill('DALF_moren');
                    var card = game.createCard(trigger.card);
                    if (card) player.gain(card, 'draw2');
                }
                event.finish();
                "step 2"
                if (result.bool) {
                    var num = parseInt(get.subtype(result.card).slice(5));
                    if (num == 1) {
                        var info = get.info(result.card);
                        if (info && info.distance && info.distance.attackFrom)
                            num = -info.distance.attackFrom + 1;
                    }
                    trigger.num += num - 2;
                }
            },
            ai: {
                threaten: 2,
            },
            derivation: ["DALF_moren_tip"]
        },
        "DALF_huanmie": {
            audio: "ext:约会大作战/audio:1",
            mod: {
                ignoredHandcard: function (card, player) {
                    if (lib.card[card.name].type == 'equip')
                        return true;
                },
                cardDiscardable: function (card, player, name) {
                    if (name == 'phaseDiscard' && lib.card[card.name].type == 'equip')
                        return false;
                },
                cardname: function (card, player) {
                    if (lib.card[card.name].type == 'equip' &&
                        player.isPhaseUsing(true) &&
                        get.position(card) == 'h') return 'sha';
                },
                selectTarget: function (card, player, range) {
                    if (card.name == 'sha' && card.cards && card.cards.length) {
                        var range2 = 1,
                            hasEquip = false;
                        for (let i of card.cards) {
                            let info = lib.card[i.name];
                            if (!info || info.type != 'equip') continue;
                            let num = parseInt(info.subtype.slice(5));
                            if (num == 1 && info && info.distance && info.distance.attackFrom)
                                num = -info.distance.attackFrom + 1;
                            if (!hasEquip) {
                                hasEquip = true;
                                range2 = num;
                            } else range2 = Math.max(num, range2);
                        }
                        range[1] += range2 - 1;
                    }
                }
            },
            trigger: {
                global: "chooseToUseBegin"
            },
            forced: true,
            filter: function (event, player) {
                if (event.type != 'respondShan') return false;
                if (!event.respondTo || !Array.isArray(event.respondTo)) return false;
                if (event.respondTo[0] != player) return false;
                var card = event.respondTo[1];
                if (card && card.name == 'sha' && card.cards && card.cards.length)
                    for (let i of card.cards)
                        if (get.type(i) == 'equip')
                            return true;
                return false;
            },
            content: function () {
                "step 0"
                var maxNum = 0,
                    list2 = [];
                for (let i of trigger.respondTo[1].cards) {
                    let info = lib.card[i.name];
                    if (!info || info.type != 'equip') continue;
                    let num = parseInt(info.subtype.slice(5));
                    if (num == 1 && info && info.distance && info.distance.attackFrom)
                        num = -info.distance.attackFrom + 1;
                    maxNum = Math.max(num, maxNum);
                }
                if (maxNum > 0)
                    for (let i = 1; i <= 13; i++)
                        if (i % maxNum == 0)
                            list2.add(i);
                var filter1 = trigger.filterCard;
                if (typeof filter1 == 'function') {
                    trigger.filterCard = function (card, player) {
                        var number = get.number(card);
                        if (number && list2.includes(number))
                            return false;
                        return filter1(card, player);
                    };
                } else {
                    trigger.filterCard = function (card, player) {
                        if (get.name(card) != 'shan') return false;
                        var number = get.number(card);
                        if (number && list2.includes(number))
                            return false;
                        return lib.filter.cardEnabled(card, player, 'forceEnable');
                    }
                }
            }
        },
        "DALF_baonve": {
            audio: "ext:约会大作战/audio:1",
            trigger: {
                player: "phaseZhunbei",
            },
            forced: true,
            content: function () {
                "step 0"
                var next = player.chooseCard('he');
                next.set('filterCard', function (card, player) {
                    return get.subtype(card) == 'equip1' && player.canRecast(card);
                });
                next.set('ai', function (card) {
                    var player = _status.event.player;
                    if (player.hp <= 2) return 20 - get.value(card);
                    var e1hs = player.countCards('he', function (cardx) {
                        return get.subtype(cardx) == 'equip1';
                    }),
                        bhs = player.countCards('he', { type: 'basic' });
                    var info = get.info(card),
                        num = 0;
                    if (info) num = parseInt(info.subtype.slice(5));
                    if (!player.hasEnabledSlot(num)) num = -2;
                    if (num == 1 && info && info.distance && info.distance.attackFrom)
                        num = -info.distance.attackFrom + 1;
                    bhs *= 2;
                    num *= 3;
                    return 3 + bhs - num - get.value(card) / 2;
                });
                next.set('prompt', '暴虐');
                next.set('prompt2', lib.translate['DALF_baonve_info']);
                "step 1"
                if (result.bool) {
                    player.recast(result.cards);
                } else {
                    player.loseHp();
                    player.showHandcards('暴虐');
                    var cards = player.getDiscardableCards(player, 'h', { type: 'basic' });
                    if (cards.length) player.discard(cards);
                }
            },
            ai: {
                threaten: 0.6,
            }
        },
        "DALF_zhongyan": {
            audio: "ext:约会大作战/audio:1",
            trigger: {
                global: "die"
            },
            forced: true,
            filter: function (event, player) {
                return event.player != player;
            },
            content: function () {
                "step 0"
                var list = [];
                for (var i = 2; i <= 5; i++)
                    if (player.hasEnabledSlot(i))
                        list.push('equip' + i);
                list.push('体力上限');
                var next = player.chooseControl(list);
                next.set('prompt', '终焉');
                next.set('prompt2', '从下列装备栏中选择一项废除之，或选择体力上限减少1点。然后你获得一个武器栏并回复1点体力。');
                next.set('ai', function (event, player) {
                    return _status.event.list[0];
                });
                next.set('list', list);
                "step 1"
                if (result.control == '体力上限') {
                    player.loseMaxHp();
                } else {
                    player.disableEquip(result.control);
                }
                player.expandEquip(1);
                player.recover();
            },
            ai: {
                threaten: 2.4,
            }
        },

    }
}